package JDBCHelper;

import TableObject.Users;
import com.mysql.jdbc.PreparedStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UsersTableUtil {
    //登陆校验
    public boolean IsUsersExist(Connection con, Users user) {
        try {
            //验证用户名存在性
            PreparedStatement pstmt;
            String sql = "select * from  users where username=? and password=?";
            pstmt= (PreparedStatement) con.prepareStatement(sql);
            pstmt.setString(1,user.getName());
            pstmt.setString(2,user.getPassword());
            ResultSet rs=pstmt.executeQuery();
            if (rs.next()) {
                //关闭数据库
                MySqlDBUtil.ShutDown(pstmt,null);
                    return true;
            }
            MySqlDBUtil.ShutDown(pstmt,null);
            return false;
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return false;
        }
    }
}
